package com.stylefeng.guns.modular.hhtb.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.modular.hhtb.model.Realname;
import com.stylefeng.guns.modular.hhtb.model.RealnameDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.hhtb.service.IRealnameService;

import java.util.List;

/**
 * 实名认证控制器

 * @author fengshuonan
 * @Date 2018-09-12 09:38:24
 */
@Controller
@RequestMapping("/realname")
public class RealnameController extends BaseController {

    private String PREFIX = "/hhtb/realname/";

    @Autowired
    private IRealnameService realnameService;

    /**
     * 跳转到实名认证首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "realname.html";
    }

    /**
     * 跳转到添加实名认证
     */
    @RequestMapping("/realname_add")
    public String realnameAdd() {
        return PREFIX + "realname_add.html";
    }

    /**
     * 跳转到修改实名认证
     */
    @RequestMapping("/realname_update/{realnameId}")
    public String realnameUpdate(@PathVariable Integer realnameId, Model model) {
        Realname realname = realnameService.selectById(realnameId);
        model.addAttribute("item",realname);
        LogObjectHolder.me().set(realname);
        return PREFIX + "realname_edit.html";
    }

    /**
     * 跳转到修改实名认证
     */
    @RequestMapping("/realname_info/{realnameId}")
    public String realnameInfo(@PathVariable Integer realnameId, Model model) {
        Realname realname = realnameService.selectById(realnameId);
        model.addAttribute("item",realname);
        LogObjectHolder.me().set(realname);
        return PREFIX + "realname_info.html";
    }

    /**
     * 获取实名认证列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(Realname realname) {
        Page<RealnameDto> page = new PageFactory<RealnameDto>().defaultPage();
        List<RealnameDto> list = realnameService.selectAll(page,realname);
        page.setRecords(list);
        return super.packForBT(page);
    }

    /**
     * 新增实名认证
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Realname realname) {
        realnameService.insert(realname);
        return SUCCESS_TIP;
    }

    /**
     * 删除实名认证
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer realnameId) {
        realnameService.deleteById(realnameId);
        return SUCCESS_TIP;
    }

    /**
     * 修改实名认证
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Realname realname) {
        realnameService.updateById(realname);
        return SUCCESS_TIP;
    }

    /**
     * 实名认证详情
     */
    @RequestMapping(value = "/detail/{realnameId}")
    @ResponseBody
    public Object detail(@PathVariable("realnameId") Integer realnameId) {
        return realnameService.selectById(realnameId);
    }
}
